package com.dapeis.core.utils.json;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.ag.utils.DateUtils;
import com.ag.utils.json.AGsonBuilder;
import com.dapeis.core.utils.DBConfigUtils;
import com.dapeis.core.utils.RequirementConfig;
import com.dapeis.domain.Requirement;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

/**
 * 
 * Title:RequirementGsonAdapter.java RequirementGsonAdapter Description:
 * 
 * @author yuanyong
 * @date 2017年5月10日 下午9:46:40 Email: hzyuanyong@126.com
 *
 */
public class RequirementGsonAdapter implements JsonSerializer<Requirement> {

    @Override
    public JsonElement serialize(Requirement src, Type typeOfSrc,
	    JsonSerializationContext context) {
	JsonObject json = new JsonObject();
	json.add(
		"scenes",
		AGsonBuilder.create().toJsonTree(
			DBConfigUtils.paserRequiremntSceneAndShop(
				src.getSceneCode(),
				RequirementConfig.CHANG_JING_PRE)));
	json.add(
		"shops",
		AGsonBuilder.create().toJsonTree(
			DBConfigUtils.paserRequiremntSceneAndShop(
				src.getShop(),
				RequirementConfig.LADY_SHOP_CHOOSE)));
	json.add(
		"costCode",
		AGsonBuilder.create().toJsonTree(
			DBConfigUtils.paserKey(src.getCostCode(),
				RequirementConfig.COST)));
	// json.addProperty("sex", src.getSex());
	// 衣橱
	json.add(
		"garderobes",
		AGsonBuilder.create().toJsonTree(
			DBConfigUtils.paserGarderobe(src.getGarderobe())));
	json.addProperty("addres", DBConfigUtils.getFullAddress(
		src.getCityCode(), src.getAddres()));
	// json.addProperty("cityCode", src.getCityCode());
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:mm");
	json.addProperty(
		"time",
		null == src.getTime() ? new String() : sdf.format(new Date(src
			.getTime() * 1000)));

	json.addProperty("typeName",
		RequirementConfig.getTypeName(src.getType()));
	json.addProperty("type", src.getType());

	json.addProperty("remark", src.getRemark());
	json.addProperty(
		"createTime",
		DateUtils.format(DateUtils.YYYY_MM_DD_HH_MM_SS,
			new Date(src.getCreateTime() * 1000)));
	return json;
    }
}
